// PROGRAMA : SCRP1000
// SISTEMA : SISP - SISTEMA DE INFORMACOES DE SEGURANCA PUBLICA
// IDENTIFICACAO CRIMINAL
// BIBLIOTECA : SISP
// ORGAO : GEJUSPC - GERENCIA DE ESTADO DA JUSTICA, SEGURANCA
// PUBLICA E CIDADANIA
// OBJETIVO : MENU PRINCIPAL DO SISTEMA
// PROGRAMADOR: JOSE ANTONIO COELHO
// DATA : 28 DE NOVEMBRO DE 1996
// ALTERACAO : 03/02/1998 POR SOLON MIRANDA

package br.com.vti.sisp_sicrim.antigo.controller.programa;

import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.controller.tela.Scrm1000;
import br.com.vti.sisp_sicrim.antigo.util.ExceptionProgram;
import br.com.vti.sisp_sicrim.antigo.util.Scrg001;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe : Scrp1000 OBJETIVO : MENU PRINCIPAL DO SISTEMA *
 * 
 * @author Incode - Data: mai/2014
 * 
 */

@Resource
@Path("/antigo/scrp1000")
public class Scrp1000 {
	Scrp1000 scrp1000Anterior;
	// Telas/paginas utilizadas
	Scrm1000 scrm1000; // Areas globais / session
	Scrg001 scrg001; // Funcoes/subrotinas
	FuncoesGerais funcoes = new FuncoesGerais();

	Result result;
	Sessao sessao;
	Boolean primeiraVez = false;
	private String wFunc = "MENU GERAL";

	private Scrm1000 preMapas() {
		sessao.getScrg001().setWVltw(3);
		sessao.getScrg001().setWProgramaw(this.getClass().getSimpleName().toUpperCase());
		sessao.getScrg001().setWFuncaow("      *** MENU PRINCIPAL ***");

		scrm1000 = new Scrm1000(true, sessao);
		scrm1000.setDataCorrente(UtilBean.obtemDataDia());
		return scrm1000;
	}

	public Scrp1000(Result result, Sessao sessao) {
		this.result = result;
		this.sessao = sessao;
	}

	@Get @Post
	public void executar(Scrm1000 scrm1000) {
		try {
			main(scrm1000);
		} catch (Exception e) {
			ExceptionProgram excp = new ExceptionProgram();
			excp.trataErroScrcerro(e, sessao, this.getClass().getSimpleName());
		}
	}

	private void main(Scrm1000 pscrm1000) {
		if (pscrm1000 == null) {
			primeiraVez = true;
			// scrm1000 = new Scrm1000 (primeiraVez);
			scrm1000 = preMapas();
			scrm1000.setNavegar("../scrp1000/executar");
			sessao.setAtributo("Scrp1000", this);
			result.include("scrm1000", scrm1000);
			scrm1000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
			return;
		} else {
			restaurarEstados(pscrm1000);
		}

		scrm1000.receberTela(false, result);

		if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) {
			Scrpp001 scrpp001 = new Scrpp001(result, sessao);
			scrpp001.executar(null);
			return;
		}

		if (scrm1000.getOpc0() == 1) {
			if (sessao.getScrg001().getWNivelw() < 4) {
				scrm1000.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1000", this);
				result.include("scrm1000", scrm1000);
				scrm1000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			Scrp110a scrp110a = new Scrp110a(result, sessao);
			scrp110a.executar(null, null, null, null, null, null);
			return;
		}

		if (scrm1000.getOpc0() == 2) {
			if (sessao.getScrg001().getWNivelw() < 4) {
				scrm1000.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1000", this);
				result.include("scrm1000", scrm1000);
				scrm1000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			Scrp120a scrp120a = new Scrp120a(result, sessao);
			scrp120a.executar(null, null, null, null, null, null, null);
			return;
		}

		if (scrm1000.getOpc0() == 3) {
			if (sessao.getScrg001().getWNivelw() < 4) {
				scrm1000.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1000", this);
				result.include("scrm1000", scrm1000);
				scrm1000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			if (sessao.getScrg001().getWMatriculaw() == 339838 || sessao.getScrg001().getWMatriculaw() == 34165) {
				Scrp130a scrp130a = new Scrp130a(result, sessao);
				scrp130a.executar(null, null, null);
				Scrpdel scrpdel = new Scrpdel(result, sessao);
				scrpdel.executar(null);
			}

			Scrp130a scrp130a = new Scrp130a(result, sessao);
			scrp130a.executar(null, null, null);
			return;
		}

		if (scrm1000.getOpc0() == 4) {
			if (sessao.getScrg001().getWNivelw() < 1) {
				scrm1000.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1000", this);
				result.include("scrm1000", scrm1000);
				scrm1000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			// FETCH 'SCRP1400'
			// PROGRAMA DE CONSULTAS COM PESQUISA FONETICA
			Scrp140a scrp140a = new Scrp140a(result, sessao);
			scrp140a.executar(null, null, null, null);
			return;
		}

		if (scrm1000.getOpc0() == 5) {
			if (sessao.getScrg001().getWNivelw() < 9) {
				scrm1000.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1000", this);
				result.include("scrm1000", scrm1000);
				scrm1000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			Scrp1600 scrp1600 = new Scrp1600(result, sessao);
			scrp1600.executar(null, null, null, null);
			return;
		}

		if (scrm1000.getOpc0() == 6) {
			if (sessao.getScrg001().getWNivelw() != 9) {
				scrm1000.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1000", this);
				result.include("scrm1000", scrm1000);
				scrm1000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			Scrp1500 scrp1500 = new Scrp1500(result, sessao);
			scrp1500.executar(null);
			return;
			/*
			 * if (UtilBean.funcao.equals(UtilBean.ctt_retorna)) { Scrp1000 scrp1000 = new Scrp1000 (); scrp1000.executar(null); return; }
			 * 
			 * switch(utils.getCursorLinhaColuna()) { // INCLUSAO case 3021 : { Scrp1510 scrp1510 = new Scrp1510 (); scrp1510.executar(); break; }
			 * 
			 * // ALTERACAO case 5022 : { Scrp1520 scrp1520 = new Scrp1520 (); scrp1520.executar(); break; }
			 * 
			 * // CONSULTA case 7023 : { Scrp1530 scrp1530 = new Scrp1530 (); scrp1530.executar(); break; }
			 * 
			 * // RELATORIO case 9024 : { scrp1540.executar(); break; }
			 * 
			 * default: { scrm1000.enviarMensagem(null, "OPCAO INVALIDA"); return; } }
			 */
		}

		if (scrm1000.getOpc0() == 7) {
			if (sessao.getScrg001().getWNivelw() < 8) {
				scrm1000.enviarMensagem(null, "USUARIO NAO AUTORIZADO");
				sessao.setAtributo("Scrp1000", this);
				result.include("scrm1000", scrm1000);
				scrm1000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
				return;
			}

			if (sessao.getScrg001().getWMatriculaw() == 339838 || sessao.getScrg001().getWMatriculaw() == 34165 || sessao.getScrg001().getWMatriculaw() == 1962893) {
				funcoes.recupdel();
			}
		}

		sessao.setAtributo("Scrp1000", this);
		result.include("scrm1000", scrm1000);
		scrm1000.enviarTela(primeiraVez, result, getClass().getSimpleName().toUpperCase());
	}

	private void restaurarEstados(Scrm1000 pscrm1000) {
		this.scrp1000Anterior = (Scrp1000) sessao.getAtributo("Scrp1000");
		if (pscrm1000 != null) {
			scrm1000 = pscrm1000;
			scrm1000.setJempresaj(sessao.getScrg001().getWEmpresaw());
			scrm1000.setJprogramaj(sessao.getScrg001().getWProgramaw());
		} else {
			scrm1000 = this.scrp1000Anterior.scrm1000;
		}
		scrm1000.setSessao(sessao);
	}
}
